package com.corewillsoft.fireflies.gamelaws;

import com.corewillsoft.fireflies.gameobjects.AreaObject;
import com.corewillsoft.fireflies.gameobjects.Firefly;
import com.corewillsoft.fireflies.gameobjects.GameObject;

public class HornetFireflyLaw extends BaseLaw {

	@Override
	public void applicate(GameObject gameObject) {
		if (gameObject instanceof Firefly)
			processFirefly((Firefly) gameObject);

	}

	/**
	 * Checks if firefly is really in the area of influence of the hornet which created this law,
	 * and if it is, makes firefly dead and invisible (hornet kills firefly)
	 * @param firefly - firefly which is affected by the hornet
	 */
	private void processFirefly(Firefly firefly) {
		//check if areas of hornet and firefly intersect
		AreaObject hornetArea = getParent().getArea();
		AreaObject fireflyArea = firefly.getArea();
		if (hornetArea.isInArea(fireflyArea) || fireflyArea.isInArea(hornetArea)) {
			//hornet kills firefly, and hides it (firefly is "eaten" and becomes invisible)
			firefly.setVisible(false);
			firefly.setAlive(false);
		}
	}

	@Override
	public LawType getType() {
		return LawType.HORNET_FIREFLY;
	}
}
